/**
 * @param {number[][]} graph
 * @return {boolean}
 */
var isBipartite = function (graph) {
  function dfs(v, graph) {
    for (let x = 0; x < graph[v].length; x++) {
      if (color[graph[v][x]] == color[v]) {
        return false;
      } else if (color[graph[v][x]] == -1) {
        color[graph[v][x]] = 1 - color[v];
        if (!dfs(graph[v][x], graph))
          return false;
      }
    }
    return true;
  }
  let color = new Array(graph.length).fill(-1);
  for (let i = 0; i < graph.length; i++) {
    if (color[i] == -1) {
      color[i] = 0;
      if (!dfs(i, graph))
        return false;
    }
  }
  return true;
};

let graph = [[1,2,3],[0,2],[0,1,3],[0,2]];
console.log(isBipartite(graph));
graph = [[1,3],[0,2],[1,3],[0,2]];
console.log(isBipartite(graph));
